//
//  JobFromYearVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/23.
//  Copyright © 2016年 阳光. All rights reserved.
//  选择从业年份界面

#import "JobFromYearVC.h"

static NSString *tableViewCellIdentifier=@"UITableViewCellIdentifier";

@interface JobFromYearVC ()<UITableViewDataSource,UITableViewDelegate,CustomNavViewDelegate>

@property(nonatomic,strong)UITableView *jobFromYearTableView;

@property(nonatomic,strong)NSMutableArray *jobFromYearArr;

@end

@implementation JobFromYearVC

-(void)leftBtnEvent
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

-(void)rightBtnEvent
{
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    CustomNavView *jobFromYearNavView=[[CustomNavView alloc]initWithTitle:@"从业年份" leftBtnImage:@"back_gray" hasLeftBtnImage:YES rightBtnTitle:nil hasRightBtnTitle:NO];
    jobFromYearNavView.delegate=self;
    jobFromYearNavView.frame=CGRectMake(0,0,APPW,64);
    [self.view addSubview:jobFromYearNavView];
    
    _jobFromYearArr=[NSMutableArray array];
    
    for (int i=2016;i>1970;i--)
    {
        [_jobFromYearArr addObject:@(i)];
    }
    
    [self initTableView];
    
}


-(void)initTableView
{
    // _jobFromYearTableView
    _jobFromYearTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,64,APPW,APPH-64) style:UITableViewStylePlain];
    _jobFromYearTableView.delegate=self;
    _jobFromYearTableView.dataSource=self;
    _jobFromYearTableView.hidden=NO;
    _jobFromYearTableView.backgroundColor=WhiteColor;
    _jobFromYearTableView.showsVerticalScrollIndicator=NO;
    _jobFromYearTableView.tableFooterView=[UIView new];
    _jobFromYearTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_jobFromYearTableView];
    [_jobFromYearTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableViewCellIdentifier];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.jobFromYearArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableViewCellIdentifier];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.textLabel.text=[NSString stringWithFormat:@"%@",self.jobFromYearArr[indexPath.row]];
    cell.textLabel.textAlignment=NSTextAlignmentCenter;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100/2;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if([self.delegate respondsToSelector:@selector(jobFromYearListWithSelectIndex:yearName:)])
    {
        [self.delegate jobFromYearListWithSelectIndex:indexPath.row yearName:[NSString stringWithFormat:@"%@",self.jobFromYearArr[indexPath.row]]];
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return kmargin*2;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footView=[UIView new];
    return footView;
}

@end
